<template>
  <div class="btn">
    <button
      v-if="!hover"
      :style="{ background: bgc }"
      :class="[
        size,
        round ? 'round' : '',
        press ? 'press' : '',
        wave ? 'wave' : '',
      ]"
    >
      {{ btnTxt }}
    </button>

    <button
      class="btn_hover"
      v-if="hover"
      :style="{ background: bgc }"
      :class="[
        size,
        round ? 'round' : '',
        press ? 'press' : '',
        wave ? 'wave' : '',
      ]"
    >
      <span> {{ btnTxt }}</span>
    </button>
  </div>
</template>

<script>
export default {
  name: 'Button',
  props: {
    hover: {
      type: Boolean,
      default: false
    },
    btnTxt: {
      type: String,
      default: 'click me'
    },
    bgc: {
      type: String,
      //   default: '#4CAF50'
      default: '#409eff'
    },
    size: {
      type: String,
      default: 'middle'
    },
    round: {
      // 是否为圆角按钮
      type: Boolean,
      default: false
    },
    press: {
      // 是否有按压效果
      type: Boolean,
      default: false
    },
    wave: {
      // 是否有波纹效果
      type: Boolean,
      default: false
    }
  }
}
</script>

<style lang="less" scoped>
.btn {
  .btn_hover {
      padding: 12px 40px!important;
    span {
      display: inline-block;
      position: relative;
      transition: 0.5s;
      &::after {
        content: ">>";
        position: absolute;
        opacity: 0;
        top: 3px;
        right: -20px;
        transition: 0.5s;
      }
    }
    &:hover span{
        padding-right: 25px;
        &::after{
            opacity: 1;
            // right: 0;
        }
    }
  }
  button {
    position: relative;
    border: none;
    color: #fff;
    border-radius: 10px;
    cursor: pointer;
    overflow: hidden;
    transition-duration: 0.4s;
    &::after {
      // 波浪效果
      content: "";
      background-color: rgba(0, 0, 0, 0.15);
      color: white;
      display: block;
      position: absolute;
      padding-top: 300%;
      padding-left: 350%;
      margin-left: -30px;
      margin-top: -120%;
      opacity: 0;
      transition: all 0.8s;
    }
    &.wave:active:after {
      // 按压效果
      padding: 0;
      margin: 0;
      opacity: 1;
      transition: 0s;
    }
  }
  .small {
    font-size: 18px;
    padding: 12px 20px;
    &.round {
      border-radius: 24px !important;
    }
    &.press {
      box-shadow: 0 6px #999;
    }
  }
  .middle {
    font-size: 28px;
    padding: 12px 24px;
  }
  .large {
    font-size: 28px;
    padding: 18px 28px;
  }
  .round {
    border-radius: 30px;
  }
  .press {
    box-shadow: 0 9px #999;
    &:active {
      box-shadow: 0 3px #666;
      transform: translateY(4px);
    }
  }
}
</style>
